

import {lc} from './../assets/unit/index'
export default {
  toComma(val){
    let str = String(val),
      newStr = "",
      count = 0,
      decimal =  str.split('.')[1];
    if(str.indexOf(".")==-1){
      for(let i=str.length-1;i>=0;i--){
        if(count % 3 == 0 && count != 0){
          newStr = str.charAt(i) + "," + newStr;
        }else{
          newStr = str.charAt(i) + newStr;
        }
        count++;
      }
      str = newStr + ".00"; //自动补小数点后两位
    }else{
      for(let i = str.indexOf(".")-1;i>=0;i--){
        if(count % 3 == 0 && count != 0){
          newStr = str.charAt(i) + "," + newStr;
        }else{
          newStr = str.charAt(i) + newStr; //逐个字符相接起来
        }
        count++;
      }
      str = newStr +'.'+ decimal;
    }
    return str;
  },
  toMoney(val){
    return '￥' + val
  },
  toDate(val){
    let value = new Date(val*1000);
    const year = value.getFullYear(),
          month = parseInt(value.getMonth())+1,
          day = value.getDate();
    return year+'-'+month+'-'+day;
  },
  getTime(val){
    return lc.getTime(val);
  },
  getDay(val){
    return lc.getDay(val);
  }
}

